package com.jason.login.controller;

import com.jason.login.constant.ResponseEnum;
import com.jason.login.pojo.Resume;
import com.jason.login.service.ResumeService;
import com.jason.login.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/addPage")
    public String addPage() {
        return "addResume";
    }


    @RequestMapping("/add")
    @ResponseBody
    public Result addResume(Resume resume) {
        resumeService.addResume(resume);
        return new Result(ResponseEnum.SUCCESS);
    }

    @RequestMapping("/updatePage")
    public ModelAndView updatePage(Long id) {
        ModelAndView mav = new ModelAndView();
        Resume resume = resumeService.queryById(id);
        mav.addObject("resume", resume);
        mav.setViewName("updateResume");
        return mav;
    }

    @RequestMapping("/update")
    @ResponseBody
    public Result updateResume(Resume resume) {
        resumeService.updateById(resume);
        return new Result(ResponseEnum.SUCCESS);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Result deleteResume(Resume resume) {
        resumeService.deleteById(resume);
        return new Result(ResponseEnum.SUCCESS);
    }


    @RequestMapping("/getResumes")
    @ResponseBody
    public Result getResumes() {
        List<Resume> resumes = resumeService.queryAll();
        Result result = new Result(ResponseEnum.SUCCESS);
        result.setData(resumes);
        return result;
    }

    @RequestMapping("/")
    public String resume() {
        return "resume";
    }
}
